package com.xyauto.uilibx.colorpicker;

import android.graphics.Color;

import java.util.Arrays;

public class ColorParams {
    private final int[] colorArray;

    public ColorParams(int[] colorArray) {
        this.colorArray = colorArray;
    }

    /**
     * 获取颜色数组
     *
     * @param layerIndex 层指针
     * @return 三色渐变组
     */
    public int[] getLayerColor(int layerIndex) {
        int start = layerIndex * BitmapColorHelper.getGradientSize();
        int[] colors = new int[BitmapColorHelper.getGradientSize()];
        if ((start + BitmapColorHelper.getGradientSize()) <= colorArray.length) {
            for (int i = 0; i < colors.length; i++) {
                int index = start + i;
                colors[i] = colorArray[index];
            }
        }
        return colors;
    }


    public int getLayerColor(int layerIndex, int colorIndex) {
        int index = layerIndex * BitmapColorHelper.getGradientSize() + colorIndex;
        if (0 <= index && index < colorArray.length) {
            return colorArray[index];
        }
        return Color.TRANSPARENT;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ColorParams params = (ColorParams) o;
        return Arrays.equals(colorArray, params.colorArray);
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(colorArray);
    }

    @Override
    public String toString() {
        return "ColorParams{" +
                "colorArray=" + Arrays.toString(colorArray) +
                '}';
    }
}
